//
//  AppDelegate+Extend.m
//  tiot
//
//  Created by admin on 2019/11/18.
//  Copyright © 2019 Kangjiedeng. All rights reserved.
//

#import "AppDelegate+Extend.h"
#import "LoginPasswordVC.h"
#import "LoginViewController.h"
#import "HomeController.h"
//
#import "LoginEmailVC.h"
#import "MainTabBarViewController.h"

@implementation AppDelegate (Extend)

#pragma mark - 初始化主窗口
- (void)initMainWindow {
    BOOL isTest = NO;//YES NO
    if(isTest){
        //测试单窗口 //mjdebug
        LoginEmailVC *loginVC = [[LoginEmailVC alloc]init];
        BasicNavigationController * nav = [[BasicNavigationController alloc]initWithRootViewController:loginVC];
        self.window.rootViewController = nav;
    }else{
        //延时进入首页0.5秒
        [NSThread sleepForTimeInterval:0.5];
        [self initRootViewController];
    }
}

#pragma mark - 显示登录界面
- (void)initRootViewController{

    NSData *userData = [MJUIUserDeFault objectForKey:Login_User];
    if (userData) {
        [UserManager.shared initUserInfo];
        MainTabBarViewController *mainVc = [[MainTabBarViewController alloc]initWithContext:nil];
        self.window.rootViewController = mainVc;
    }else{
        LoginPasswordVC *loginVC = [[LoginPasswordVC alloc]init];
        BasicNavigationController * nav = [[BasicNavigationController alloc]initWithRootViewController:loginVC];
        self.window.rootViewController = nav;
    }
}

#pragma mark - 配置UI 全局样式
- (void)configAppearanceStyle {
    
    //初始化语言
    [LanguageHelper initSystemLanguage];
    
    //关闭QMUI发送分析
    QMUIConfiguration.sharedInstance.sendAnalyticsToQMUITeam = false;

    /*键盘设置*/
    // 设置键盘自动弹起
    [IQKeyboardManager sharedManager].enable = true;
    // 是否添加键盘上的toolBar
    [IQKeyboardManager sharedManager].enableAutoToolbar = true;
    // 当键盘弹起时，点击背景，键盘就会收回
    [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = true;
    //toolbar 右键设置完成
    [IQKeyboardManager sharedManager].toolbarDoneBarButtonItemText = MJUILocalizedString(@"Done");
}

#pragma mark - 注册第三方服务
- (void) registerService:(NSDictionary *)launchOptions {
    
    [self configBugly];
    [self configMobSDK];
}

#pragma mark - MobSDK
- (void)configMobSDK{
//    [MobSDK registerAppKey:kMobAppKey appSecret:kMobAppSecret];
//    [MobSDK uploadPrivacyPermissionStatus:YES onResult:nil];
}

#pragma mark - Bugly
- (void)configBugly{
//    BuglyConfig *buglyConfig = [[BuglyConfig alloc] init];
//    buglyConfig.debugMode = true;
//    buglyConfig.reportLogLevel = BuglyLogLevelInfo;
//    [Bugly startWithAppId:kBuglyAppId config:buglyConfig];
    
    if([MJHelper isDebug]){
        [Bugly startWithAppId:kBuglyAppId];
    }else{
        [Bugly startWithAppId:kDisBuglyAppId];
    }
}

#pragma mark - 强制使用系统键盘
- (BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(NSString *)extensionPointIdentifier {
    if(MJHelper.shared.disableThirdPartyKeyboard){
        if ([extensionPointIdentifier isEqualToString:@"com.apple.keyboard-service"]) {
            return NO;
        }
    }
    return YES;
}

@end
